package com.qiangesoft.blog.controller.common;

import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.core.pojo.vo.WebSiteInfoVO;
import com.qiangesoft.blog.core.service.impl.HomeServiceImpl;
import com.qiangesoft.blog.system.authentication.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * <p>
 * 公共接口 前端控制器
 * </p>
 *
 * @author qiange
 */
@Api(tags = "公共模块")
@RestController
@RequestMapping("/common")
@RequiredArgsConstructor
public class CommonController {

    private final LoginService loginService;
    private final HomeServiceImpl homeService;


    @GetMapping(value = "/captcha")
    @ApiOperation(value = "获取验证码")
    public ResponseResult getCode() throws IOException {
        Map<String, String> result = loginService.getCode();
        return ResponseResult.success("获取验证码成功", result);
    }

    @GetMapping(value = "/webInfo")
    @ApiOperation(value = "网站信息")
    public WebSiteInfoVO webSiteInfo() {
        return homeService.webSiteInfo();
    }

    @GetMapping(value = "/report")
    @ApiOperation(value = "增加访问量")
    public ResponseResult report(HttpServletRequest request) {
        homeService.report(request);
        return ResponseResult.success();
    }
}

